#include <bits/stdc++.h>
using namespace std;
int tree[10010];
int main() {
  int L, M;
  cin >> L >> M;
  for (int i = 0; i <= L; i++) {
    tree[i] = 1;
  }
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      tree[j] = 0;
    }
  }
  int sum=0;
  for (int i = 0; i <= L; i++) {
    if(tree[i] == 1) sum++;

  }
  cout<<sum;

  return 0;
}